<!DOCTYPE html>
<html lang="zh">

<head>
  <meta charset="UTF-8" />
  <meta name="referrer" content="no-referrer" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  <link rel="stylesheet" href="css/public.css" />
  <link rel="stylesheet" href="css/style2.css" />
  <link rel="stylesheet" href="css/style_media.css" />
  <link rel="icon" href="favicon.ico" type="image/x-icon" />
  <title>源·梦登录系统</title>
</head>

<body>
  <header>
    <div class="nav-left">
      <img src="./image/logo.png" alt="logo" />
      <a href="javascript:void(0)">登录系统</a>
    </div>
    <div class="nav-right">
      <ul>
        <li><a href="javascript:void(0)">在线登录</a></li>
        <li><a href="javascript:void(0)">在线注册</a></li>
        <li><a href="javascript:void(0)">历史记录</a></li>
        <li><a href="javascript:void(0)">个人信息</a></li>
      </ul>
    </div>
  </header>
  <main>
    <!-- 表单内容 -->
    <div class="register-box">
      <form action="" method="Post">
        <div class="register">
          <!-- 头像 -->
          <div class="picture">
            <img id="avatar" src="./image/picture.png" alt="头像" />
          </div>
          <label for="username"></label><input name="username" id="qqNumber" type="text" placeholder="请输入账号" />
          <label for="password"></label><input name="password" id="password" type="password" placeholder="请输入密码" />
          <label for="confirmPwd"></label><input name="confirmPwd" id="confirmPwd" type="password"
            placeholder="请再次输入密码" />
          <label for="phone"></label><input name="phone" id="phone" type="text" placeholder="请输入手机号" />
          <div class="order">
            <a href="/">已有账号?点击登录</a>
          </div>
          <input id="submit" type="button" value="注册" />
        </div>
      </form>
    </div>
  </main>
  <footer>赣ICP备2020014038号</footer>
  // qq头像获取
  <script src="./js/interface.js"></script>
  <script src="./js/axios.js"></script>
  <script>
    let username = document.querySelector('#qqNumber')
    let password = document.querySelector('#password')
    let confirmPwd = document.querySelector('#confirmPwd')
    let phone = document.querySelector('#phone')
    let register = document.querySelector('#submit')
    let avatar = document.querySelector('#avatar')
    // 注册点击事件
    register.addEventListener('click', () => {
      let notNull = username.value != '' && password.value != '' && confirmPwd.value != '' && phone.value != ''
      if (notNull) {
        // 非空且密码相同时发送axios请求
        if (password.value === confirmPwd.value) {
          axios({
            url: 'http://localhost:8080/register',
            method: 'post',
            data: {
              username: username.value,
              password: password.value,
              confirmPwd: confirmPwd.value,
              phone: phone.value,
              avatar: avatar.src
            }
          }).then(res => {
            console.log(res.data);
          })
          alert('注册成功,即将跳转到首页');
          location.href = '/'
        } else {
          alert('两次输入的密码不一致')
        }
      }
      else {
        alert('你还有未输入的表单喔~')
      }
    })


  </script>
</body>

</html>